<?php
    include_once(DAO_PATH . "/ProductDAO.php");
    include_once(OBJECT_PATH . "/Product.php");
?>

<form id="editProductForm" name="editProductForm" action="products.php?action=edit" method="POST">

    <div class="form-label">Select Product to edit:</div>
    <div class="form-component">
        <!-- Get the products from the database and populate the list -->
        <select name="productId" onchange="autoCompleteEditForm()">
            <option value="0">Select:</option>
            <?php
            $dao = new ProductDAO();
            $list = $dao->getProductList();

            // iterate through the ArrayObject list
            $iterator = $list->getIterator();
            while ($iterator->valid())
            {
                $product = $iterator->current();
                ?>
                <option value="<?php echo $product->getId(); ?>"><?php echo $product->getName(); ?></option>
                <?php
                $iterator->next();
            }
            ?>
        </select>
    </div>

    <div style="margin-top: 30px; clear: both;"></div>

    <div class="form-title">Edit Product</div>

    <div class="form-label">Name:</div>
    <div class="form-component"><input type="text" name="name" /></div>

    <div class="form-label">Description:</div>
    <div class="form-component"><input type="text" name="description" /></div>

    <div style="margin-top: 30px; clear: both;"></div>

    <div class="form-subtitle">Select the components of the product:</div>

    <?php include_once(VIEW_PATH . "/ProductCatList.php"); ?>

    <div style="margin-top: 30px; clear: both;"></div>

    <div class="form-subtitle">Enter the price of the product:</div>

    <div class="form-label">Retail Price ($):</div>
    <div class="form-component"><input type="text" name="retailprice" /></div>

    <div style="text-align: center;"><input type="submit" value="Submit" name="Submit" /></div>

</form>

